<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/view/include/taglib.jsp"%>
<html lang="cn" class="app">
<head>
    <title>后台管理 - 栏目表</title>
    <meta name="description" content="app, web app, responsive, admin dashboard, admin, flat, flat ui, ui kit, off screen nav" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <link rel="icon" type="image/png" href="icon.png">
    <link rel="apple-touch-icon-precomposed" href="icon.png">
    <link rel="stylesheet" href="${ctxStatic}/js/jPlayer/jplayer.flat.css" type="text/css" />
    <link rel="stylesheet" href="${ctxStatic}/css/bootstrap.css" type="text/css" />
    <link rel="stylesheet" href="${ctxStatic}/css/animate.css" type="text/css" />
    <link rel="stylesheet" href="${ctxStatic}/css/font-awesome.min.css" type="text/css" />
    <link rel="stylesheet" href="${ctxStatic}/css/simple-line-icons.css" type="text/css" />
    <link rel="stylesheet" href="${ctxStatic}/css/font.css" type="text/css" />
    <link rel="stylesheet" href="${ctxStatic}/css/app.css" type="text/css" />
    <link rel="stylesheet" href="${ctxStatic}/js/ztree/css/zTreeStyle.css" />
    <link rel="stylesheet" href="${ctxStatic}/js/chosen/chosen.css" type="text/css" />
    <link rel="stylesheet" href="${ctxStatic}/js/layui/css/layui.css">
    <!--[if lt IE 9]>
    <script src="${ctxStatic}/js/ie/html5shiv.js"></script>
    <script src="${ctxStatic}/js/ie/respond.min.js"></script>
    <script src="${ctxStatic}/js/ie/excanvas.js"></script>
    <![endif]-->
</head>

<body>
<section class="scrollable wrapper">
    <div class="row">
        <div class="col-lg-12">
            <!-- 引导开始 -->
            <ul class="breadcrumb">
                <li><a href="${ctx}/welcome"><i class="fa fa-home"></i> 主页</a></li>
                <li>文章管理</li>
                <li class="active">栏目管理</li>
                <li class="active">栏目编辑</li>
            </ul>
            <!-- 引导结束 -->
        </div>
    </div>
    <form id="cmsCategoryForm" class="bs-example form-horizontal" method="post" >
        <%--基本信息--%>
        <section class="panel panel-default">
            <header class="panel-heading font-bold">栏目编辑</header>

            <div class="panel-body">
                <input type="hidden" name="id" value="${cmsCategory.id}"/>
                <input type="hidden" id="parentId" name="parentId" value="${trainSpecial.parentId}" />
            <%--<div class="form-group">--%>
                    <%--<label class="col-lg-2 col-md-2 col-sm-2 control-label"><span class="text-danger">*</span>站点编号：</label>--%>
                    <%--<div class="col-lg-10 col-md-10 col-sm-10">--%>
                        <%--<input id="siteId" type="text" class="form-control" name="siteId" placeholder="站点编号" value="${cmsCategory.siteId}" required />--%>
                    <%--</div>--%>
                <%--</div>--%>
                <div class="form-group">
                    <label class="col-lg-2 col-md-2 col-sm-2 control-label"><span class="text-danger">*</span>所属栏目：</label>
                    <div class="col-lg-2 col-md-2 col-sm-2">
                        <input id="parentNm"  class="form-control" name="parentNm" placeholder="所属栏目" <c:if test="${cmsCategory.parentId=='0'}">value="栏目管理"</c:if> value="${cmsCategory.cmsCategory.name}" readonly />
                    </div>
                    <div class="col-lg-2 col-md-2 col-sm-2 ">
                        <button id="menuBtn" type="button" class="btn btn-s-md btn-default">选择</button>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-lg-2 col-md-2 col-sm-2 control-label"><span class="text-danger">*</span>栏目名称：</label>
                    <div class="col-lg-4 col-md-4 col-sm-4">
                        <textarea id="name" type="text" class="form-control" name="name" placeholder="栏目名称(不超过100字)"  maxlength="100" required>${cmsCategory.name}</textarea>
                    </div>
                </div>
                <%--<div class="form-group">--%>
                    <%--<label class="col-lg-2 col-md-2 col-sm-2 control-label">模块 默认导航：</label>--%>
                    <%--<div class="col-lg-4 col-md-4 col-sm-4">--%>
                        <%--<textarea id="module" type="text" class="form-control" name="module" placeholder="模块默认导航(不超过50字)"  maxlength="50" required>${cmsCategory.module}</textarea>--%>
                    <%--</div>--%>
                <%--</div>--%>
                <%--<div class="form-group">--%>
                    <%--<label class="col-lg-2 col-md-2 col-sm-2 control-label">是否在首页显示：</label>--%>
                    <%--<div class="col-lg-4 col-md-4 col-sm-4">--%>
                        <%--<select name="showHome" class="form-control" >--%>
                            <%--<c:forEach items="${yn}" var="m">--%>
                                <%--<option value="${m.value}"<c:if test="${cmsCategory.showHome==m.value}">selected="selected"</c:if>>${m.label}</option>--%>
                            <%--</c:forEach>--%>
                        <%--</select>--%>
                    <%--</div>--%>
                <%--</div>--%>
                <%--<div class="form-group">--%>
                    <%--<label class="col-lg-2 col-md-2 col-sm-2 control-label">是否有下级导航：</label>--%>
                    <%--<div class="col-lg-4 col-md-4 col-sm-4">--%>
                        <%--<select name="isBy" class="form-control" >--%>
                            <%--<c:forEach items="${yn}" var="m">--%>
                                <%--<option value="${m.value}"<c:if test="${cmsCategory.isBy==m.value}">selected="selected"</c:if>>${m.label}</option>--%>
                            <%--</c:forEach>--%>
                        <%--</select>--%>
                    <%--</div>--%>
                <%--</div>--%>
                <%--<div class="form-group">--%>
                    <%--<label class="col-lg-2 col-md-2 col-sm-2 control-label">自定义视图：</label>--%>
                    <%--<div class="col-lg-4 col-md-4 col-sm-4">--%>
                        <%--<input id="customView" type="text" class="form-control" name="customView" placeholder="自定义视图" value="${cmsCategory.customView}" required />--%>
                    <%--</div>--%>
                <%--</div>--%>

                <%--<div class="form-group">--%>
                    <%--<label class="col-lg-2 col-md-2 col-sm-2 control-label">访问地址：</label>--%>
                    <%--<div class="col-lg-4 col-md-4 col-sm-4">--%>
                        <%--<textarea id="href" type="text" class="form-control" name="href" placeholder="访问地址(不超过200字)"  maxlength="200" required >${cmsCategory.href}</textarea>--%>
                    <%--</div>--%>
                <%--</div>--%>
                <div class="form-group">
                    <label class="col-lg-2 col-md-2 col-sm-2 control-label">备注信息：</label>
                    <div class="col-lg-4 col-md-4 col-sm-4">
                        <textarea id="remarks" class="form-control" name="remarks" placeholder="备注信息(不超过200字)" maxlength="200" required >${cmsCategory.remarks}</textarea>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-lg-offset-2 col-md-offset-2 col-sm-offset-2 col-lg-10 col-md-10 col-sm-10">
                        <shiro:hasPermission name="cms:cmsCategory:update">
                            <button type="button" class="btn btn-s-md btn-info" onclick="updatecmsCategory()">保存</button>
                        </shiro:hasPermission>
                        <button type="button" class="btn btn-s-md btn-danger" onclick="goBack(${cmsCategory.id})">关闭</button>
                    </div>
                </div>
            </div>
        </section>
    </form>
</section>
<div id="menuContent" class="menuContent" style="display:none;position: absolute;z-index: 10000;background-color: #eee;border: 1px solid #ccc;">
    <style>.line{height:auto;}</style><%--这个不能删除--%>
    <ul id="tree" class="ztree" style="margin-top:0;"></ul>
</div>
</body>

<script src="${ctxStatic}/js/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="${ctxStatic}/js/bootstrap.js"></script>
<!-- App -->
<script src="${ctxStatic}/js/app.js"></script>
<script src="${ctxStatic}/js/slimscroll/jquery.slimscroll.min.js"></script>
<script src="${ctxStatic}/js/app.plugin.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/jPlayer/jquery.jplayer.min.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/jPlayer/add-on/jplayer.playlist.min.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/jPlayer/demo.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/tools.js?version=${ctxVersion}"></script>
<script type="text/javascript" src="${ctxStatic}/js/page/paging.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/layer/layer.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/tmpl/jquery.tmpl.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/chosen/chosen.jquery.min.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/layui/layui.all.js"></script>
<script src="${ctxStatic}/js/ztree/js/jquery.ztree.core-3.5.min.js"></script>

<script>
    $(function(){
        var msg = '${msg}';
        if(msg!=''){
            showMsg(msg);
        }
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            //日期
            laydate.render({
                elem: '#showDate'
            });
        });
    })

    function updatecmsCategory(){
        if(isBlankCheck("parentNm,name","所属栏目,栏目名称")) {
            var loadingLayer = layer.load(1, {shade: [0.1, '#fff']});//loading
            //根据项目标识获取目录
            $.ajax({
                type: 'post',
                url: '${ctx}/cms/cmsCategory/update.json?timeStamp=' + new Date().getTime(),
                dataType: "json",
                data: $("#cmsCategoryForm").serialize(),
                success: function (data) {
                    layer.close(loadingLayer);
                    showMsg(data.desc, function () {
                        if (data.ret == 1) {//成功
                            location.href = "${ctx}/cms/cmsCategory/update?id=" + data.data;
                        }
                    });
                }, error: function () {
                    layer.close(loadingLayer);
                    showMsg("点击过快或程序异常");
                }
            });
        }
    }

   /* /!** 关闭当前弹出框并执行 *!/
    function closeSelfModel(){
        var index = parent.layer.getFrameIndex(window.name);
        parent.searchPage(1);//执行父页面的搜索功能
        parent.layer.close(index);
    }*/
    //关闭弹出框
    function goBack(id) {
        location.href = "${ctx}/cms/cmsCategory/list?id="+id;
    }
</script>
<script>
    $(function(){
        var setting = {
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback : {
                onClick : function(event, treeId, treeNode) {
                    //点击回调方法
                    ztreeOnClickCall && ztreeOnClickCall(treeNode);
                    $("#parentNm").val(treeNode.name);
                    hideMenu();
                }
            }
        };
        var zNodes =[
            {id:"0",name:"栏目管理",open:true},
            <c:forEach items="${cmsCategoryList}" var="o" varStatus="status">
            { id:"${o.id}", pId:"${o.parentId}", name:"${o.name}", open:true}<c:if test="${!status.last}">,</c:if>
            </c:forEach>
        ];
        $(document).ready(function(){
            var ztree = $.fn.zTree.init($("#tree"), setting, zNodes);
            ztree.expandAll(true);
        });

        $("#menuBtn").click(showMenu);
    })

    //ztree点击回调
    function ztreeOnClickCall(treeNode){
        $("#parentId").val(treeNode.id);
    }
    //展示树选择区域
    function showMenu() {
        var cityObj = $("#parentNm");
        var cityOffset = $("#parentNm").offset();
        $("#menuContent").css({
            left: cityOffset.left + "px",
            top: cityOffset.top + cityObj.outerHeight() + "px"
        }).slideDown("fast");

        $("body").bind("mousedown", onBodyDown);
    }
    //隐藏树选择区域
    function hideMenu() {
        $("#menuContent").fadeOut("fast");
        $("body").unbind("mousedown", onBodyDown);
    }
    //点击其他区域事件-用于隐藏选择树
    function onBodyDown(event) {
        if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length > 0)) {
            hideMenu();
        }
    }

</script>
</html>
